<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="com.cms.biz.category.CategoryHelper"%>
<%@page import="com.cms.menu.MenuHelper"%>
<%@page import="java.sql.*, java.util.*, com.cms.config.*, com.cms.facade.*,com.cms.util.*,com.cms.bean.*,com.cms.database.DBHelper"%>
<%@page import="org.apache.log4j.Logger"%>
<%@taglib uri="/i18n-1.0" prefix="i18n"%>
<%
	response.setContentType("text/html; charset=UTF-8");
	SysConfigBean sysbean = ApplicationHelper.getApplicationSysConfigBean(session);
	Connection conn = DBHelper.getConn();
	int menuId = StringHelper.isRequestParamEmptyInt(request, "menuId", 0);
	int categoryTypeId = StringHelper.isRequestParamEmptyInt(request, "categoryTypeId", CategoryTypeDef.NEW);
	List<CategoryBean> list = ApplicationHelper.getApplicationSubCategoryListById(session, categoryTypeId);
	int new_product_id = SequenceHelper.getSeqNextVal(conn, SequenceHelper.PRODUCTS_SEQ);
%>
<i18n:bundle baseName="i18n-ebizport" locale="<%=SessionFacade.getLocale(session)%>"/>
<html>
<head>
<meta name="keywords" content="<%=sysbean.getWebKey()%>" />
<meta name="description" content="<%=sysbean.getWebDesc()%>" />
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><%=sysbean.getWebName()%></title>
<link rel="stylesheet" href="<%=URLPath.CSS_DIR%>/global.css" type="text/css" media="screen" />
<link rel="stylesheet" href="<%=URLPath.CSS_DIR%>/admin.css" type="text/css" media="screen" />
<link rel="stylesheet" href="<%=URLPath.CSS_DIR%>/uploadify.css" type="text/css" media="screen" />
<script type="text/javascript" src="<%=URLPath.JS_DIR%>/jquery-1.9.1.js"></script>
<script type="text/javascript" src="<%=URLPath.JS_DIR%>/jquery.uploadify.js"></script>
<script type="text/javascript" src="<%=URLPath.JS_DIR%>/main.js"></script>
<script type="text/javascript" src="<%=URLPath.JS_DIR%>/ckeditor/ckeditor.js"></script>
<script src="<%=URLPath.JS_DIR%>/layer.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	
	 $("#cover_upload").uploadify({ 
		 'formData'  : {'uploadtype' : '4', 'infoId' : '<%=new_product_id%>'},
         'swf'       : '/js/uploadify.swf',
         'uploader'         : '/servlet/uploadFilesServlet',
         'buttonText' : '\u9009\u62e9\u4ea7\u54c1\u5c01\u9762',
         'auto' : false,
         'fileSizeLimit' : '3000KB',
         'fileTypeDesc' : '\u56fe\u7247\u6587\u4ef6',
         'fileTypeExts' : '*.gif; *.jpg; *.png',
         'multi' : false,
         'method' : 'post',
         'uploadLimit' : 1,
         'removeCompleted' : false,
         'queueID' : 'coverQueue',
         'progressData' : 'speed',
         'onUploadSuccess' : function(file, data, response){
         }
     });
	 
	 $("#pictures_upload").uploadify({
		 'formData'  : {'uploadtype' : '5', 'infoId' : '<%=new_product_id%>'},
         'swf'       : '/js/uploadify.swf',
         'uploader'  : '/servlet/uploadFilesServlet',
         'buttonText' : '\u9009\u62e9\u4ea7\u54c1\u7167\u7247',
         'auto' : false,
         'fileSizeLimit' : '3000KB',
         'fileTypeDesc' : '\u56fe\u7247\u6587\u4ef6',
         'fileTypeExts' : '*.gif; *.jpg; *.png',
         'multi' : true,
         'method' : 'post',
         'removeCompleted' : false,
         'queueID' : 'picturesQueue',
         'progressData' : 'speed',
         'onUploadSuccess' : function(file, data, response){
         }
     });

	 
	 $("#addproduct").on('click',function(){
		 if(!checkFormItemNotNull()) return;
		 if(isEmpty(CKEDITOR.instances.ckeditorText.getData())){
			 layer.alert('\u5185\u5bb9\u4e0d\u80fd\u4e3a\u7a7a!', 8);
			 return; 
		 }

		 $('#cover_upload').uploadify('upload','*');
		 $('#pictures_upload').uploadify('upload','*');
		 document.myform.submit();
	 });
	 CKEDITOR.replace('ckeditorText');
     <%
     if(RequestFacade.getSuccessFlag(request)){
          out.print("layer.alert('<"+request.getParameter("title")+"> \u53d1\u5e03\u6210\u529f!', 9);");	 
     }else if(!StringHelper.isEmpty(RequestFacade.getErrorMsg(request))){
    	  out.print("layer.alert('\u53d1\u5e03\u5931\u8d25,\u9519\u8bef\u4fe1\u606f:"+RequestFacade.getErrorMsg(request)+"!', 8);");
     }
     %>
});

	function checkFormItemNotNull() {
		var flag = true;
		$("select,input[notnull='true']").each(function() {
			if($(this).is("input")&&isEmpty($(this).val())
					||($(this).is("select")&&$(this).val()=='-1')
					||($(this).is("textarea")&&isEmpty($(this).val()))){
				layer.alert($(this).attr('desc')+'\u4e0d\u80fd\u4e3a\u7a7a!', 8);
				$(this).focus();
				flag=false;
				return false;
			}	
		});
		return flag;
	}
	
</script>
<style type="text/css">
a.but{
   background-color:#2ECC71;
   vertical-align:middle; 
   padding:5px 8px 5px 8px;
   text-align:center;
   line-height:40px;
   color:#FFF;
}
a.but:hover{
   background-color:#27AE60;
   cursor:hand;
}


</style>
</head>
<body>

<div class="admin-menu-nav">
   <ul >
     <li style="width:49.9%"><span class="menu-nav"><i18n:message key="now_position"/>:&nbsp;<%=MenuHelper.getMenuPath(session, menuId) %></span></li>
     <li style="width:50%"><span class="menu-button" id="addproduct"><i18n:message key="publish"/></span></li>
   </ul>   
</div>
<form name="myform" action="<%=URLPath.ADMIN_URL %>"  method="post" target="_self">
<input type="hidden" name="token" value="<%=request.getAttribute("token")%>">
<input type="hidden" name="cmd" value="AddProduct"/>
<input type="hidden" name="doNothing" value="N"/>
<input type="hidden" name="menuId" value="<%=menuId %>"/>
<input type="hidden" name="category" value="<%=categoryTypeId%>"/>
<input type="hidden" name="productId" value="<%=new_product_id%>"/>
<div class="mainDiv">
   <table class="dialogs">
      <tr>
         <td class="title"><i18n:message key="product.name"/>:</td>
         <td><input type="text" class="u-ipt-w300" name="title" value="" notnull="true" desc="<i18n:message key='product.name'/>"/></td>
      </tr>
      <tr>
         <td class="title"><i18n:message key="type"/>:</td>
         <td>
         <select name="subcategory" class="u-ipt-w180" style="height:28px" notnull="true" desc="<i18n:message key='type'/>">
            <option value="-1"><i18n:message key="please_select"/>
            <%
            if(list!=null&&list.size()>0){ 
                for(CategoryBean cBean:list){
             	   List<CategoryBean> subList = cBean.getChildCategoryBeans();
            %>
                   <optgroup label="<%=cBean.getName() %>">
                   <%
                   if(subList!=null&&subList.size()>0){
                	   for(CategoryBean subBean:subList){
                   %>
                       <option value="<%=subBean.getId() %>"><%=subBean.getName() %>
                   <%} }%>
                   </optgroup>
            <%} }%>
         </select>
         </td>
      </tr>
      <tr>
         <td class="title"><i18n:message key='product.cover'/></td>
         <td>
            <div id="coverQueue"></div>
            <input type="file" name="cover_upload" id="cover_upload" />
         </td>
      </tr>
      <tr>
         <td class="title"><i18n:message key="product.pictures"/></td>
         <td>
            <div id="picturesQueue"></div>
            <input type="file" name="pictures_upload" id="pictures_upload" />
         </td>
      </tr>       
      <tr>
         <td class="title"><i18n:message key="product.explain"/>:</td>
         <td><textarea id="ckeditorText" cols="80" name="content" rows="10"></textarea></td>
      </tr>
   </table>

</div>
</form>
</body>
</html>
<% DBHelper.closeConn(conn);%>